#ifndef _MYSQL_CONNECTION_POOL_H_
#define _MYSQL_CONNECTION_POOL_H_

#include <string>
#include <vector>


#include <log4cxx/logger.h>

#include "MysqlConnPool.h"
#include "MysqlConnPtr.h"

using std::string;
using std::vector;

using namespace log4cxx;

struct MYSQL_POOL_ITEM {
	MYSQL * mysql;
	bool is_in_use;
};

class MysqlConnPool {

	public:
		int init(const char * svr_ip, unsigned short svr_port, const char * svr_username, const char * svr_password, \
			const char * db_name, int pool_max_size);
		int get(MysqlConnPtr & ptr);
		int release(const int index);

	protected:
		int reconnect(int index);

	private:
		string _svr_ip;
		unsigned short _svr_port;
		string _svr_username;
		string _svr_password;
		string _db_name;
		int _pool_max_size;
		vector<MYSQL_POOL_ITEM> _conns;
		static LoggerPtr _logger;
		pthread_mutex_t _mutex;
};
		
#endif
